package com.dmxtechnologies.community.rar.api;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dmxtechnologies.community.pojo.DateList;

/* Represents the response to a client from the EIS */
public class CMSBaseResponse implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8147503890770890291L;
	// 总页数
	protected int totalPage;
	// 总记录数
	protected int totalSize;
	// 内容列表
	protected List<DateList> dataList;
	//图片访问地址
	protected String smallPicURL;
	
	public CMSBaseResponse(String json,String smallPicURL) {
		List<DateList> list = new ArrayList<>();
		if(json != null){
//			StringReader reader = new StringReader(json.replaceAll("\r\n",""));
//			JsonObject jsonObject=Json.createReader(reader).readObject(); 
			JSONObject jsonObject = JSONObject.parseObject(json.replaceAll("\r\n",""));
			this.totalPage = jsonObject.getInteger("totalPage");
			this.totalSize = jsonObject.getInteger("totalSize");
			this.smallPicURL = smallPicURL;
			JSONArray jsonArray = jsonObject.getJSONArray("dataList");
			for (int idx= 0; idx < jsonArray.size(); idx++) {
				DateList dList = setValues(jsonArray.getJSONObject(idx), idx);
				list.add(dList);
            }
			this.dataList = list;
		}
	}

	private DateList setValues(JSONObject jsonObject, int idx) {
		DateList dList = new DateList();
		dList.setId(jsonObject.getInteger("id"));
		dList.setTitle(jsonObject.getString("title"));
		dList.setBigpic(jsonObject.getString("bigpic"));
		dList.setSmallpic(jsonObject.getString("smallpic"));
		dList.setExt1(jsonObject.getString("ext1"));
		dList.setExt2(jsonObject.getString("ext2"));
		dList.setExt3(jsonObject.getString("ext3"));
		dList.setExt4(jsonObject.getString("ext4"));
		return dList;
	}

	public CMSBaseResponse() {
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(int totalSize) {
		this.totalSize = totalSize;
	}

	public List<DateList> getDataList() {
		return dataList;
	}

	public void setDataList(List<DateList> dataList) {
		this.dataList = dataList;
	}

	public String getSmallPicURL() {
		return smallPicURL;
	}

	public void setSmallPicURL(String smallPicURL) {
		this.smallPicURL = smallPicURL;
	}
	

}
